package com.wkl.yuyue.utils;

import com.wkl.yuyue.entity.User;
import com.wkl.yuyue.service.IClassesService;
import com.wkl.yuyue.service.ICourseService;
import com.wkl.yuyue.service.IDepService;
import com.wkl.yuyue.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private IUserService iUserService;
    @Autowired
    private IClassesService iClassesService;
    @Autowired
    private IDepService iDepService;
    @Autowired
    private ICourseService iCourseService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        User sysUser = iUserService.selectUserByName(username);
        if (!Objects.isNull(sysUser)) {
            passwordService.validate(sysUser);
            return CreateLoginUser(sysUser);
        }
        else {
            throw new RuntimeException("用户不存在");
        }
    }

    private UserDetails CreateLoginUser(User sysUser) {
        User loginUser = sysUser;
        return loginUser;
    }
}
